package com.tanhua.server.controller;

import com.tanhua.model.vo.PageResult;
import com.tanhua.server.service.CommentService;
import org.bson.types.ObjectId;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/comments")
public class CommentController {

    @Autowired
    private CommentService commentService;

    /**
     *   获取评论列表
     * @param result
     * @param movementId
     * @return
     */
    @GetMapping
    public ResponseEntity commentsList(PageResult result,@RequestParam ObjectId movementId){
        PageResult pageResult = commentService.commentsList(result,movementId);

        return ResponseEntity.ok(pageResult);
    }

    /**
     *      评论动态
     * @param params
     * @return
     */
    @PostMapping
    public ResponseEntity content(@RequestBody Map<String,String> params){
        commentService.content(params);
        return ResponseEntity.ok(null);
    }

    /**
     *      点赞评论
     * @return
     */
    @GetMapping("/{id}/like")
    public ResponseEntity likeComment(@PathVariable ObjectId id){

        Integer count = commentService.likeComment(id);
        return ResponseEntity.ok(count);
    }

    @GetMapping("/{id}/dislike")
    public ResponseEntity dislikeComment(@PathVariable ObjectId id){
        Integer count = commentService.dislikeComment(id);
        return ResponseEntity.ok(count);
    }
}
